<extend name="Public/base"/>

<block name="body">
  <!-- 标题栏 -->
  <div class="main-title">
    <h2>[{$model['title']}] 列表</h2>
  </div>

  <!-- 数据列表 -->
  <form id="form1" name="form1" action="{:U('Admin/Ticketorder/data_export')}" method="post" class="form-horizontal">
    <div class="order_filter">
      <div class="grid">
        <div class="date">
          <input type="text" class="form-control begin_time" name="begin_time" placeholder="请选择开始日期" value="{$default_filter['begin_time']}">
        </div>
      </div>
      <div class="grid">
        <div class="date">
          <input type="text" class="form-control end_time" name="end_time" placeholder="请选择结束日期" value="{$default_filter['end_time']}">
        </div>
      </div>
      <div class="grid">
        <div class="date">
          <select class="form-control ex-select" name="ex_id" onchange="choseExhibition(this)">
            <option value="">全部展览</option>
            <volist name="exhibitions" id="exhibition">
              <option value="{$exhibition.id}">{$exhibition.name}</option>
            </volist>
          </select>
        </div>
      </div>
      <div class="grid">
        <div class="date">
          <select class="form-control ticket-select" name="ticket_id">
            <option value="">全部票种</option>
          </select>
        </div>
      </div>
      <!-- <div class="grid">
        <div class="date">
          <select class="form-control" name="status">
            <option value="">全部状态</option>
            <option value="0">未兑换</option>
            <option value="1">已兑换</option>
          </select>
        </div>
      </div> -->
      <div class="form-item cf grid" style="text-align: right;">
        <button class="btn btn-primary" type="button" onclick="clearFilter()">清空</button>
        <button class="btn btn-primary" type="button" onclick="filter()">筛选</button>
        <button class="btn btn-primary" type="submit" target-form="form-horizontal">导 出</button>
      </div>
    </div>
  </form>

  <div class="filter-count">
    <ul>
      <li>
        <b>{$count}</b>
        <p>订单数</p>
      </li>
      <li>
        <b>{$filter_count['total_amount']}</b>
        <p>票务数</p>
      </li>
      <li>
        <b>￥{$filter_count['total_price']}</b>
        <p>订单金额(已支付)</p>
      </li>
      <li>
        <b>{$filter_count['total_redeemed']}</b>
        <p>兑换数</p>
      </li>
      <li>
        <b>￥{$filter_count['total_redeem_price']}</b>
        <p>兑换金额</p>
      </li>
    </ul>
  </div>

  <div class="cf">
    <div class="fl">
      <empty name="model.extend">
       <div class="tools">
        <!-- <a class="btn btn-primary" href="{:U('add?model='.$model['id'])}">新 增</a> -->
        <!-- <button class="btn ajax-post confirm btn-primary" target-form="ids" url="{:U('del?model='.$model['id'])}">删 除</button> -->
      </div>
    </empty>
  </div>
  <!-- 高级搜索 -->
  <!-- <div class="search-form cf">
   <div class="sleft">
    <input type="text" name="{$model['search_key']|default='title'}" class="search-input" value="{:I('title')}" placeholder="请输入关键字">
    <a class="sch-btn" href="javascript:;" id="search" url="{:U('Think/lists','model='.$model['name'],false)}"><i class="btn-search"></i></a>
  </div>

  </div> -->
</div>


<!-- 数据列表 -->
<div class="data-table">
  <div class="data-table table-striped">
    <table>
      <!-- 表头 -->
      <thead>
        <tr>
          <th class="row-selected row-selected">
            <input class="check-all" type="checkbox">
          </th>
          <volist name="list_grids" id="field">
            <th>{$field.title}</th>
          </volist>
        </tr>
      </thead>

      <!-- 列表 -->
      <tbody>
        <volist name="list_data" id="data">
          <tr>
            <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
            <volist name="list_grids" id="grid">
              <td>{:get_list_field($data,$grid)}</td>
            </volist>
          </tr>
        </volist>
      </tbody>
    </table>
  </div>
</div>
<div class="page">
  {$_page|default=''}
</div>
</block>

<block name="script">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
  <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
  <script type="text/javascript">
  $(function(){
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
    var query  = $('.search-form').find('input').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
  });

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
      if(event.keyCode===13){
        $("#search").click();
      }
    });

    $('.begin_time').datetimepicker({
      format: 'yyyy-mm-dd',
      language:"zh-CN",
      minView:2,
      autoclose:true
    });

    $('.end_time').datetimepicker({
      format: 'yyyy-mm-dd',
      language:"zh-CN",
      minView:2,
      autoclose:true
    });

    var default_ex_id = GetQueryString("ex_id")?GetQueryString("ex_id"):null;
    var default_ticket_id = GetQueryString("ticket_id")?GetQueryString("ticket_id"):null;

    if(default_ex_id){
      $(".ex-select").val(default_ex_id); 
      $.ajax({
        type : 'get',
        url : 'index.php?s=Admin/Ticketorder/getTickets&ex_id='+default_ex_id,
        success: function(data){
          if(data.status==0){
            alert(data.info);
          }else{
            var html="<option value=''>全部票种</option>";
            var item = data.info;
            for(var i in item){
              html +='<option value="'+item[i]['id']+'" >'+item[i]['name']+'</option>';
            }
            $(".ticket-select").html(html);
            $(".ticket-select").val(default_ticket_id);
          }
        }
      });
    }
  })

  function choseExhibition(value){
    var selectedOption = value.options[value.selectedIndex];
    var ex_id = selectedOption.value;
    if(ex_id!=''){
      $.ajax({
        type : 'get',
        url : 'index.php?s=Admin/Ticketorder/getTickets&ex_id='+ex_id,
        success: function(data){
          if(data.status==0){
            alert(data.info);
          }else{
            var html="<option value=''>全部票种</option>";
            var item = data.info;
            for(var i in item){
              html +='<option value="'+item[i]['id']+'" >'+item[i]['name']+'</option>';
            }
            $(".ticket-select").html(html);
          }
        }
      });
    }
  }

  function filter(){
    var begin_time = $('.begin_time').val();
    var end_time = $('.end_time').val();
    var ex_id = $("select[name='ex_id']").val();
    var ticket_id = $("select[name='ticket_id']").val();
    window.location.href = 'index.php?s=Admin/Ticketorder/lists&model=ticket_order&begin_time='+begin_time+'&end_time='+end_time+'&ex_id='+ex_id+'&ticket_id='+ticket_id;
  }

  function GetQueryString(name)
  {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
  }

  function clearFilter(){
    window.location.href = 'index.php?s=Admin/Ticketorder/lists&model=ticket_order';
  }
  </script>
</block>
